/*
 * (c) Copyright 2014 Hewlett-Packard Development Company, L.P. All rights reserved.
 */
package com.hp.snap.gr.utils.eium;

import java.io.File;
import java.util.Map;

import com.hp.siu.utils.SIUInfo;
import com.hp.snap.gr.exception.GRMException;
import com.hp.snap.gr.utils.GRMConfigManager;

/**
 * @since 3.2
 * @author Yang, Lin
 * 
 */
public class SIUInfoUtils {
    private static volatile boolean initialized = false;

    public static final String IORURL = "IORURL";
    public static final String VARROOT = "VARROOT";

    public static synchronized void init() throws GRMException {
        if (initialized) {
            return;
        }

        /* load /etc/opt/SIU_${USER}/SIU.ini */
        GRMConfigManager.initGRLocalConfig(null);

        Map<String, String> eiumConfig = GRMConfigManager.getEiumConfig();

        // URL to configuration server
        SIUInfo.getInstance().setIORURL(eiumConfig.get(IORURL));
        // secured IUM
        SIUInfo.getInstance().setVarRoot(eiumConfig.get(VARROOT));

        // security
        if (SIUInfo.getInstance().isSecure()) {
            System.setProperty("java.security.auth.login.config", eiumConfig.get(VARROOT) + File.separator
                    + "security-login.config");
        }

        initialized = true;
    }
}
